/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.kaoshi.jeeweb.modules.sample.service;

import com.kaoshi.jeeweb.common.service.CrudService;
import com.kaoshi.jeeweb.common.service.base.BaseGenericService;
import com.kaoshi.jeeweb.common.utils.CacheUtils;
import com.kaoshi.jeeweb.modules.sample.dao.SampleSearchDao;
import com.kaoshi.jeeweb.modules.sample.entity.SampleSearch;
import com.kaoshi.jeeweb.modules.sys.utils.DictUtils;
import com.kaoshi.myweb.common.seachable.Criteria;
import com.kaoshi.myweb.common.seachable.QueryCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 字典Service
 * @author ThinkGem
 * @version 2014-05-16
 */
@Service
@Transactional(readOnly = true)
public class SampleSearchService extends BaseGenericService<SampleSearch, String> {

	@Autowired
	private SampleSearchDao dao;

	@Autowired
	public void setGenericDAO(SampleSearchDao dao){
		setDao(dao);
	}

	/**
	 * 查询字段类型列表
	 * @return
	 */
	public List<String> findTypeList(){
		return dao.findTypeList(new SampleSearch());
	}

	@Transactional(readOnly = false)
	public void save(SampleSearch sampleSearch) {
		dao.insert(sampleSearch);
		CacheUtils.remove(DictUtils.CACHE_DICT_MAP);
	}

	@Transactional(readOnly = false)
	public void delete(String id) {
		super.deleteByPrimaryKey(id);
		CacheUtils.remove(DictUtils.CACHE_DICT_MAP);
	}

	public List<SampleSearch> findList(SampleSearch entity) {
		QueryCondition condition = new QueryCondition();
		condition.or(Criteria.newCriteria().eq("del_flag", entity.getDelFlag()).eq("type", entity.getType()).like("description", "%" + entity.getDescription() + "%"));
		return dao.queryByCondition(condition);
	}

}
